<?php

namespace App\Http\Controllers\Admin;

use App\Http\Controllers\Controller;
use App\Models\AdminAgencys;
use Illuminate\Http\Request;

class IndexController extends Controller
{

    public function index()
    {
        return view('admin.index.index');
    }

    /**
     * 代办数据
     * @route admin.index.agencys
     * @param type 类型：1店铺 2活动 3商品 4需求 5快速发布需求
     */
    public function agencys(Request $request)
    {
        try {
            $list = [];
            $list['store'] = AdminAgencys::where(['type' => 1,'is_read' => 1,'status' => 1])->count();
            $list['act'] = AdminAgencys::where(['type' => 2,'is_read' => 1,'status' => 1])->count();
            $list['goods'] = AdminAgencys::where(['type' => 3,'is_read' => 1,'status' => 1])->count();
            $list['demand'] = AdminAgencys::where(['type' => 4,'is_read' => 1,'status' => 1])->count();
            $list['quick'] = AdminAgencys::where(['type' => 5,'is_read' => 1,'status' => 1])->count();
            $list['act_order'] = AdminAgencys::where(['type' => 6,'is_read' => 1,'status' => 1])->count();
            $list['goods_order'] = AdminAgencys::where(['type' => 7,'is_read' => 1,'status' => 1])->count();
            $list['cash_out'] = AdminAgencys::where(['type' => 8,'is_read' => 1,'status' => 1])->count();
            $list['bond_return'] = AdminAgencys::where(['type' => 9,'is_read' => 1,'status' => 1])->count();
            return $this->writeJson(0, $list);
        } catch (\Exception $e) {
            return $this->writeJson(1, null, $e->getMessage());
        }
    }

    /**
     * 代办改为已读
     * @route admin.index.AgencysStatus
     * @param type 类型：1店铺 2活动 3商品 4需求 5快速发布需求
     */
    public function AgencysStatus(Request $request)
    {
        try {
            $params = [
                'type' => (int)$request->post('type'),
                'is_read' => 1,
                'status' => 1,
            ];
            $ids = AdminAgencys::where($params)->pluck('id');
            AdminAgencys::whereIn('id',$ids)->update(['is_read' => 2]);
            return $this->writeJson(0, null,'操作成功');
        } catch (\Exception $e) {
            return $this->writeJson(1, null, $e->getMessage());
        }
    }

}